package main

import (
	"strconv"
	"time"

	_ "gitee.com/lzqysoft/ims/initial"
	_ "gitee.com/lzqysoft/ims/routers"

	"github.com/astaxie/beego"
	"github.com/astaxie/beego/orm"

	// _ "github.com/lib/pq"

	"gitee.com/lzqysoft/ims/controllers"
	//"gitee.com/lzqysoft/qysoft/jobs"
	//	"github.com/beego/i18n"
	"github.com/astaxie/beego/plugins/cors"
)

func init() {
	// orm.RegisterDataBase("default", "postgres", "postgres://ilive:ilive@192.168.1.128:5432/ilive?sslmode=disable")
	//	beego.SetLevel(beego.LevelInformational)
	orm.DefaultTimeLoc = time.UTC
	if beego.BConfig.RunMode == "dev" {
		beego.BConfig.WebConfig.DirectoryIndex = true
		beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
		beego.SetLevel(beego.LevelDebug)
		//orm.Debug = true
	}
}

func main() {
	beego.SetLogger("file", `{"filename":"logs/app.log"}`)
	beego.BConfig.WebConfig.StaticDir["/imgs"] = "imgs"
	beego.BConfig.Log.AccessLogs = true
	logLevel, _ := strconv.Atoi(beego.AppConfig.String("log_level"))
	if beego.BConfig.RunMode == "prod" {
		beego.SetLevel(logLevel)
	}
	beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
		AllowOrigins:     []string{"*"},
		AllowMethods:     []string{"OPTIONS", "HEAD", "GET", "POST", "PUT", "PATCH", "DELETE"},
		AllowHeaders:     []string{"Origin", "Accept", "Content-Type", "Authorization", "x-requested-with", "X-Requested-With"},
		ExposeHeaders:    []string{"Content-Length"},
		AllowCredentials: true,
	}))
	beego.ErrorController(&controllers.ErrorController{})
	//jobs.InitJobs()
	beego.Run()
}
